/**
 * 
 */
package org.ztest.lambda;

import java.util.Arrays;
import java.util.HashMap;
import java.util.function.Supplier;

/**
 * Java8 Method Reference examples
 * 
 * @author lhl
 *
 *         2015年11月4日 下午1:54:30
 */
public class MethodReference
{
	public void test(String[] args)
	{
		// Lambda expression
		Arrays.sort(args, (a, b) -> compare1(a, b));

		// Method reference
		Arrays.sort(args, MethodReference::compare1);

		System.out.println(Arrays.toString(args));

		System.out.println(get(HashMap::new));
	}

	public static int compare1(String arg1, String arg2)
	{
		return arg1.length() - arg2.length();
	}

	public static <T> T get(Supplier<T> source)
	{
		return source.get();
	}
}
